import java.util.*;
import java.awt.*;

public class Client {
  private LoginGUI LoginView;
  private MainGUI MainView;
  private Player thePlayer;
  private Map theMap;// Map stored on the client
  private ArrayList<Move> MoveOrder;
  private ArrayList<Attack> AttackOrder;
  private ArrayList<Territory> UpdatedTerritory;
  private int turnmark;
  
  public void SetUpGame(int m, int n) { //run the login window
	  ArrayList<Territory> InitialTerritory = new ArrayList<Territory>();
	  thePlayer = new Player("Default", 0, Color.white, InitialTerritory);// Initialization of the player
	  theMap = new Map(m, n);
      MoveOrder = new ArrayList<Move>();
      AttackOrder = new ArrayList<Attack>();
	  
      LoginView = new LoginGUI(thePlayer);
  }
 
  public void StartPlaying(){//after connect to the server, run the main window
	  turnmark = 0;
	  MainView = new MainGUI(this);
  }  
  
  public void StartTurn(ArrayList<Territory> UpdatedTerritory){

	  theMap.SetupMap(UpdatedTerritory);
	  MainView.Update();
	  turnmark++;
	  
	  for (Territory t: UpdatedTerritory){
		  if ((t.GetOwner() == thePlayer)&&
		     (! thePlayer.GetTerritoryList().contains(t)))	//player got new territory    		  
		       thePlayer.AddTerritoryList(t); 
		  if ((t.GetOwner() != thePlayer)&&
		     (thePlayer.GetTerritoryList().contains(t))) // player lost territory
		       thePlayer.RemoveTerritoryList(t);
	  }
	  thePlayer.ComputeAmount();
	  
	  for (Territory t : thePlayer.GetTerritoryList()){
			  t.SetUpdated(false);
			  t.ClearAttacker();
			  t.AddAmount(1);
	  }
	  MoveOrder.clear();
	  AttackOrder.clear();
  }
   
  public void SubmitOrder(){// send the move order list and attack order list to the server
		//send move order list
		  //send attack order list
  }

  public void FinishGame(){
	  FinishBox gameover = new FinishBox(this);
  }
  
  public void WatchTurn(){
	  theMap.SetupMap(UpdatedTerritory); 
  }
  public Player GetPlayer(){
	  return thePlayer;
  }
  public Map GetMap(){
	  return theMap;
  }
  public int GetTurnMark(){
	  return turnmark;
  }
  public void addMove(Move newmove){
	  MoveOrder.add(newmove);
  }
  public void addAttack(Attack newattack){
	  AttackOrder.add(newattack);
  }
 	 
  public static void main(String[] args) {
	  Client theClient = new Client();
      theClient.SetUpGame();
  }
}
